package com.tl.sun.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * 作者：HQY on 16/11/2 11:25
 * 邮箱：hqy_xz@126.com
 */

public class IpSQLiteHelper extends SQLiteOpenHelper {


    private static String name = "IP.db";
    private static Integer version = 1;

    public IpSQLiteHelper(Context context) {
        super(context, name, null, version);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {
        //执行有更改的sql语句
        db.execSQL("create table ips(id integer primary key autoincrement,ip varchar(255))");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {
        db.execSQL("DROP TABLE IF EXISTS ips");
        onCreate(db);
    }

    /**
     * 插入数据
     *
     * @param ip
     */
    public void save(String ip) {
        SQLiteDatabase db = getWritableDatabase();
        db.execSQL("insert into goods (ip) values(?)",
                new Object[]{ip});

    }

    /**
     * 删除所有
     */
    public void deleteAll() {
        SQLiteDatabase db = getWritableDatabase();
        db.execSQL("delete from goods");
    }


    public void updateIP() {


    }


}
